package com.tgky.ybzb.controller;

import com.tgky.ybzb.common.Result;
import com.tgky.ybzb.neo4j.entity.NodeEntityObj;
import com.tgky.ybzb.neo4j.entity.PersonWithRelationship;
import com.tgky.ybzb.neo4j.service.NodeObjServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Lixx
 * @date 2024/9/4 9:24
 */
@RestController
@Slf4j
@Api(tags = "知识图谱模块")
@RequestMapping("zstp")
public class NodeObjController {

    @Autowired
    private NodeObjServiceImpl iNodeObjService;

    /**
     * 导入知识图谱保存
     * @param map
     * @return
     */
    @ApiOperation(value = "导入知识图谱保存和保存坐标")
    @PostMapping("/importZstp")
    public Result saveimportZstp(@RequestBody Map<String,Object> map) {
        return Result.success(iNodeObjService.saveimportZstp(map));
    }


    /**
     * 新增节点和更新节点属性内容(id必须相同才会更新)
     * @param map
     * @return
     */
    @ApiOperation(value = "新增节点和更新节点属性内容")
    @PostMapping("/saveNode")
    public Result<List<NodeEntityObj>> saveNodeData(@RequestBody Map<String,Object> map) {
        return Result.successData(iNodeObjService.saveNodeData(map));
    }
    /**
     * 根据id删除节点
     * @return
     */
    @ApiOperation(value = "删除节点")
    @GetMapping("/deleteNode")
    public Result deleteNodeData(@RequestParam("id") String id) {
        return Result.success(iNodeObjService.deleteNodeData(id));
    }

    /**
     * 根据id删除两个节点之间的关系
     * @return
     */
    @ApiOperation(value = "删除节点关系")
    @GetMapping("/deleteEdge")
    public Result deleteEdgeData(@RequestParam("id") String id) {
        return Result.success(iNodeObjService.deleteEdgeData(id));
    }

    /**
     * 创建两个节点的关系
     * @return
     */
    @ApiOperation(value = "创建关系")
    @PostMapping("/createEdge")
    public Result createEdgeData(@RequestBody NodeEntityObj nodeEntityObj) {
        return Result.success(iNodeObjService.createEdgeData(nodeEntityObj));
    }

    /**
     * 查出所有节点的节点信息(下拉框选择)
     * @return
     */
    @ApiOperation(value = "所有节点的节点信息(下拉框选择)")
    @GetMapping("/nodeList")
    public Result<List<NodeEntityObj>> getNodeList() {
        return Result.successData(iNodeObjService.getNodeList());
    }

    /**
     * 根据类型和条件查出所有节点信息
     * @return
     */
    @ApiOperation(value = "查出所有节点和关系信息")
    @GetMapping("/allNode")
    public Result<PersonWithRelationship> getAllNodeData(@RequestParam(value = "type",required = false) String type,
                                                               @RequestParam(value = "condition",required = false) String condition,
                                                               @RequestParam(value = "chartType",required = false) String chartType,
                                                               @RequestParam(value = "skip",required = false) String skip) {
        return Result.successData(iNodeObjService.getAllNodeData(type,condition,chartType,skip));
    }

}
